<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/commons/global.jsp" %>
<style>
</style>
<script type="text/javascript">
    var noticeDataGrid_${type};
    $(function() {
        noticeDataGrid_${type} = $('#noticeDataGrid_${type}').datagrid({
            url : '${path}/notice/dataGrid?type=${type}',
            striped : true,
            rownumbers : true,
            pagination : true,
            singleSelect : true,
            idField : 'id',
            sortName : 'id',
            sortOrder : 'asc',
            pageSize : 20,
            pageList : [ 10, 20, 30, 40, 50, 100, 200, 300, 400, 500 ],
            columns : [ [
                {
                width : '100',
                title : 'id',
                field : 'id'
                ,hidden : true
            },
                {
                width : '200',
                title : '标题',
                field : 'title',
                formatter:function(value,row,index){
                	var newImg="";
                	if(row.readed==0){
                		newImg="<img src='${ctxPath}/static/img/news.gif'>";
                	}
                	return newImg+value;
                }
            },
                {
                width : '120',
                title : '创建时间',
                field : 'createTime',
                formatter:function(value,row,index){
                	return datetime2Str(value);
                }
            },
            ]],
            frozenColumns : [ [{
                field : 'action',
                title : '操作',
                width : 200,
                formatter : function(value, row, index) {
                    var str = '';
                    str += $.formatString('<a href="javascript:void(0)" class="notice-easyui-linkbutton-edit" data-options="plain:true,iconCls:\'fi-pencil icon-blue\'" onclick="editNoticeFun_${type}(\'{0}\');" >编辑</a>', row.id);
                    str += '&nbsp;&nbsp;|&nbsp;&nbsp;';
                    str += $.formatString('<a href="javascript:void(0)" class="notice-easyui-linkbutton-del" data-options="plain:true,iconCls:\'fi-x icon-red\'" onclick="deleteNoticeFun_${type}(\'{0}\');" >删除</a>', row.id);
                      str += '&nbsp;&nbsp;|&nbsp;&nbsp;';
                    str += $.formatString('<a href="javascript:void(0)" class="notice-easyui-linkbutton-view" data-options="plain:true,iconCls:\'fi-magnifying-glass\'" onclick="viewNoticeFun_${type}(\'{0}\');" >查看</a>', row.id);
                    return str;
                }
            } ] ],
            onLoadSuccess:function(data){
                $('.notice-easyui-linkbutton-edit').linkbutton({text:'编辑'});
                $('.notice-easyui-linkbutton-del').linkbutton({text:'删除'});
                $('.notice-easyui-linkbutton-view').linkbutton({text:'查看'});
            },
            toolbar : '#noticeToolbar_${type}'
        });
    });

    function addNoticeFun_${type}() {
         parent.$.modalDialog({
            title : '添加',
            width : '80%',
            height : '80%',
            href : '${path}/notice/addPage?type=${type}',
            buttons : [ {
                text : '确定',
                handler : function() {
                    parent.$.modalDialog.openner_dataGrid = noticeDataGrid_${type};//因为添加成功之后，需要刷新这个treeGrid，所以先预定义好
                    var f = parent.$.modalDialog.handler.find('#noticeAddForm');
                    f.submit();
                }
            } ]
        }); 
    }

    function editNoticeFun_${type}(id) {
        if (id == undefined) {
            var rows = noticeDataGrid_${type}.datagrid('getSelections');
            id = rows[0].id;
        } else {
            noticeDataGrid_${type}.datagrid('unselectAll').datagrid('uncheckAll');
        }
        parent.$.modalDialog({
            title : '编辑',
            width : '80%',
            height : '80%',
            href : '${path}/notice/editPage/' + id,
            buttons : [ {
                text : '确定',
                handler : function() {
                    parent.$.modalDialog.openner_dataGrid = noticeDataGrid_${type};//因为添加成功之后，需要刷新这个dataGrid，所以先预定义好
                    var f = parent.$.modalDialog.handler.find('#noticeEditForm');
                    f.submit();
                }
            } ]
        });
    }

    function deleteNoticeFun_${type}(id) {
        if (id == undefined) {//点击右键菜单才会触发这个
            var rows = noticeDataGrid_${type}.datagrid('getSelections');
            id = rows[0].id;
        } else {//点击操作里面的删除图标会触发这个
            noticeDataGrid_${type}.datagrid('unselectAll').datagrid('uncheckAll');
        }
        parent.$.messager.confirm('询问', '您是否要删除吗？', function(b) {
            if (b) {
                progressLoad();
                $.post('${path}/notice/delete/'+id, {}
                , function(result) {
                    if (result.success) {
                        parent.$.messager.alert('提示', result.msg, 'info');
                        noticeDataGrid_${type}.datagrid('reload');
                    }
                    progressClose();
                }, 'JSON');
            }
        });
    }
     function viewNoticeFun_${type}(id) {
        if (id == undefined) {
            var rows =  noticeDataGrid_${type}.datagrid('getSelections');
            id = rows[0].id;
        } else {
             noticeDataGrid_${type}.datagrid('unselectAll').datagrid('uncheckAll');
        }
        parent.$.modalDialog({
            title : '查看',
            width : '80%',
            height : '80%',
            href : '${path}/notice/viewPage/' + id,
            buttons:[{
            	text:'关闭',
            	 handler : function() {
            		 noticeDataGrid_${type}.datagrid('reload');
            		 parent.$.modalDialog.handler.dialog('close');
            	 }
            }]
        });
    }
     
     function searchNoticeFun_${type}(){
    	 noticeDataGrid_${type}.datagrid('load', $.serializeObject($('#searchNotice_${type}')));
     }
     
     function cleanNoticeFun_${type}(){
    	 $('#searchNotice_${type} input').val('');
    	 noticeDataGrid_${type}.datagrid('load', {});
     }
</script>
<div class="easyui-layout" data-options="fit:true,border:false">
                                            <div data-options="region:'center',border:false">
        <table id="noticeDataGrid_${type}" data-options="fit:true,border:false"></table>
    </div>
</div>
<div id="noticeToolbar_${type}" style="display: none;">
	<form id="searchNotice_${type}">
            <table>
                <tr>
                    <td>标题名称:</td>
                    <td><input name="title" placeholder="" class="easyui-text" style="width:200px"/>
                          <a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'fi-magnifying-glass',plain:true" onclick="searchNoticeFun_${type}();">查询</a>
                        <a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'fi-x-circle',plain:true" onclick="cleanNoticeFun_${type}();">清空</a>
                    </td>
                </tr>
            </table>
        </form>
    <a onclick="addNoticeFun_${type}();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'fi-plus icon-green'">添加</a>
</div>
